package com.server.net.message;

import com.msg.MsgMain;
import io.netty.channel.Channel;
import io.netty.util.AttributeKey;
import lombok.Data;

/**
 * 传给业务层的协议包
 * 包含协议内容及session
 */
@Data
public class MsgPack {
    private MsgMain.MainProtocl mainProtocl;
    private Channel channel;
    private int msgIndex;
    private static AttributeKey<String> key = AttributeKey.valueOf("token");//依附于Channel。共生

    public MsgPack(int msgIndex, MsgMain.MainProtocl mainProtocl, Channel channel) {
        this.mainProtocl = mainProtocl;
        this.channel = channel;
        this.msgIndex = msgIndex;
    }

    public String getToken() {
        return channel.attr(this.key).get();
    }

    public void setToken(String token) {
        channel.attr(this.key).set(token);
    }

}
